<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String strUserId = request.getSession().getAttribute("stxtUName").toString();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">    
    <link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/ext-all.css">  
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/edit-grid.css">  
	<script type="text/javascript" src="<%=path%>/js/ext/adapter/ext/ext-base.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/ext-all.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/DWRTreeLoader.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/SearchField.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/query-dwr-proxy.js"></script>	
	<script type="text/javascript" src="<%=path%>/js/ext/ext-lang-zh_CN.js"></script>
	<script type='text/javascript' src='/btsm/dwr/interface/JFolderBeb.js'></script>
	<script type='text/javascript' src='/btsm/dwr/engine.js'></script>
	<script type='text/javascript' src='/btsm/dwr/util.js'></script>	 		
  </head>
  
  <body>
	<div id="westDiv">		
		<div id="folderTree" style="height:80%"/>
		<div id="otherTree"/>
		<div id="comTree"/>
	</div>	
	<div id="contentDiv" style="width:100%;height:100%;align=center;">
	<form id="downForm" action="<%=path%>/DownLoadServlet">
		<input type="hidden" name="strDownFileID" id="strDownFileID_ID">
	</form>

  
<script type="text/javascript">
var contextMenu;//右键菜单 
var folderWindow;
var folderForm; 
var ds;
var fileEditWindow;
var selectFolderId;
Ext.form.Field.prototype.msgTarget = 'side'; 
Ext.onReady(function()
{   
  
	var winUpload;
	var FormUpload = function(){
			this.folderParentIDTextField = {
					xtype : 'hidden',
					readOnly : true,
					allowBlank:false,
					name : 'strFolderParentID'
				};
			this.parentFolderNameTextField = {
					xtype : 'hidden',
					readOnly : true,
					name : 'strFolderParentName'
				};
			this.uploadFileNameTextField = {
					xtype: 'textfield',    
					fieldLabel: '文件名',    
					name: 'file',    
					width:300 ,
					inputType: 'file',//文件类型  
					allowBlank:false,
			        blankText :'请选择上传的文件'					
			};	
						
			FormUpload.superclass.constructor.call(this, {
					bodyStyle : 'padding:5px 5px 0',
					frame : true,
					id: 'FormUpload',
					labelAlign: 'right',
					width:400 ,
					labelWidth:50,
					url: '<%=path%>/UploadServlet',
					fileUpload: true, 
					items : [this.folderParentIDTextField, 
							 this.parentFolderNameTextField,
							 this.uploadFileNameTextField
							 ]
				});	
	}	
	
	Ext.extend(FormUpload, Ext.form.FormPanel);		
		
	var UploadWindow = function() {
		var _win = this;
		this.formPanel = new FormUpload();
		var _form = this.formPanel.getForm();
		UploadWindow.superclass.constructor.call(this, {
			title : '文件上传',
			width : 400,
			height : 150,
			resizable : true,
			plain : false,
			border : false,
			modal : true,
			autoScroll : false,
			layout : 'fit',
			closeAction : 'hide',
			items : this.formPanel,
			buttonAlign:'center',
			buttons : 
			[
				{	text : ' 上传',
					handler : function() 
					{
						if (_form.isValid()) 
						{
							var form = _form.getValues(false);
							var strFolderId = form.strFolderParentID;
							var fileName = form.file;

							/*
							JFolderBeb.isFileExists(strFolderId,fileName,function(data)
							{
								if(!data)
								{
									Ext.Msg.alert("警告","该文件已经存在，请重新选择上传文件!");
								}	
							})*/

							
							_form.submit(
							{  
								success: function(form, action){
									Ext.Msg.alert('成功', action.result.msg,function()
									{
										_win.hide();
										ds.load({params:{start:0, limit:17,id: _form.strFolderParentID,strUserID:'<%=strUserId%>'}});
									}); 
									
								},  
								failure: function(form, action){  
									Ext.Msg.alert('错误', action.result.msg,function()
									{
										_win.hide();
										ds.load({params:{start:0, limit:17,id: _form.strFolderParentID,strUserID:'<%=strUserId%>'}});
									});  
								},
								waitMsg : '正在上传数据，稍后...'
							});
						}
					}
				},{
					text : '取消',
					handler : function() {
						_win.hide();
					},
					tooltip : '关闭对话框'
				}
			]	
		});
	}
	Ext.extend(UploadWindow, Ext.Window);

	winUpload = new UploadWindow();	
		
	var folderTreeDiv = Ext.get("folderTree");	
	var Tree = Ext.tree;    
    var folderRoot = new Tree.AsyncTreeNode({
           text: '个人文档', 
		   icon:'/btsm/js/ext/resources/images/user.gif',
           draggable:false, 
           id:'0'
     });	 
	var treePanel = new Ext.tree.TreePanel( {
		el : "folderTree",
		border : false,
		animate : true,
		autoHeight : true,
		height:folderTreeDiv.getComputedHeight(),
		rootVisible : true,
		autoScroll : true,
		containerScroll : true,
		loader : new Ext.tree.DWRTreeLoader( {
			dwrCall:JFolderBeb.getFolders,queryParam:{id:0,strUserID:'<%=strUserId%>',strDepth:1}
		}),
		root : folderRoot
	});
	treePanel.render();
	folderRoot.expand(true,true);	

	
	var rootOhter = new Ext.tree.TreeNode({
					id:"otherRooot",
					icon:'/btsm/js/ext/resources/images/group.png',
					text:"他人共享"
			  });
	var treeOther = new Ext.tree.TreePanel({
        renderTo:"otherTree",
        root:rootOhter,//定位到根节点
        animate:true,//开启动画效果
        enableDD:false,//不允许子节点拖动
        border:false,//没有边框
        rootVisible:true//设为false将隐藏根节点，很多情况下，我们选择隐藏根节点增加美观性
    });
	
	/*
	var rootCom = new Ext.tree.TreeNode({
					id:"root",
					icon:'/btsm/js/ext/resources/images/gears.gif',
					text:"单位文档"
			  });
			  
	var treeCom = new Ext.tree.TreePanel({
        renderTo:"comTree",
        root:rootCom,//定位到根节点
        animate:true,//开启动画效果
        enableDD:false,//不允许子节点拖动
        border:false,//没有边框
        rootVisible:true//设为false将隐藏根节点，很多情况下，我们选择隐藏根节点增加美观性
    });*/
	
	var btnAddFolder = new  Ext.Button({
					text:'创建文件夹',
					pressed:false,					 
					handler:createChild
				});
	var btnEditFolder = new  Ext.Button({
					text:'修改文件夹',
					pressed:true,					 
					handler:updateNode
				});			
	var btnDeleteFolder = new  Ext.Button({
					text:'删除文件夹',
					pressed:true,					 
					handler:removeNode
				});
	btnAddFolder.disable();
	btnEditFolder.disable();
	btnDeleteFolder.disable();
  var viewport = new Ext.Viewport({
	    layout:'border',
	    frame:true,
	    items:[
	    	{
		        region: 'west',
		        contentEl: 'westDiv',
		        margins:'110 5 30 5',
		        split: true,
		        border: true,
		        collapsible: true,
		        width: 200,
				tbar: [btnAddFolder,btnEditFolder,btnDeleteFolder]
		    },
	    	{
		        //title: '文档资料 ',
		        region: 'center',
		        contentEl: 'contentDiv',
		        margins:'110 30 30 5',
		        split: true,
		        border: true	
		    }]
		});
	
	function showUploadWin()
	{
		var selectNode = treePanel.getSelectionModel().getSelectedNode();
		
		if(!selectNode || selectNode.id === "0")
		{			 
			Ext.Msg.alert("提示","请先选文件夹路径!");
			return;			 
		}
		var data = {'strFolderParentID':selectNode.id,
					'strFolderParentName':selectNode.text,
					'file':''
					};
		var record = new Ext.data.Record(data);
		winUpload.show();
		winUpload.formPanel.getForm().reset();
		winUpload.formPanel.getForm().setValues({});
		winUpload.formPanel.getForm().setValues(data);
		
	}
	
  
	
	treePanel.on('checkchange', function(node, checked) 
	{      
		if(checked)
		{       
			var chs  = treePanel.getChecked();   
			for(var i = 0; i < chs.length; i++) 
			{   
				if (chs[i].attributes['id'] != node.attributes['id'])
				{   
					chs[i].attributes.checked = false;
					chs[i].ui.toggleCheck(false);    
				}
				
			}
			treePanel.getSelectionModel().select(node);
		}
	});
	
	
	function checkchange(node,checked)
	{
		node.attributes.checked = checked; 
		node.ui.toggleCheck(checked)
		if(checked)
		{
			var chs  = treePanel.getChecked(); 
			for(var i = 0; i < chs.length; i++) 
			{   
				if (chs[i].attributes['id'] != node.attributes['id'])
				{   
					chs[i].attributes.checked = false;
					chs[i].ui.toggleCheck(false);    
				}
			}
		}
		
	}
		
	//文件夹form
	folderForm = function(){
			this.idTextField = {
					xtype : 'hidden',
					readOnly : true,
					name : "strFolderID"
				};
			this.idParentFolderTextField = {
					xtype : 'hidden',
					readOnly : true,
					name : "strParentFolderID"
				};
			this.folderNameTextField = {
					xtype : 'textfield',
					fieldLabel : "文件夹名称",
					allowBlank : false,
					name : "strFolderName",
					width:160,
					blankText :'请输入文件夹名称'	
			};	
						
			folderForm.superclass.constructor.call(this, {
					bodyStyle : 'padding:5px 5px 0',
					frame : true,
					id: 'folderForm',
					labelAlign: 'right',
					labelWidth:80,
					items : [this.idTextField, 
							 this.idParentFolderTextField,
							 this.folderNameTextField
							 ]
				});	
	}	
	
	Ext.extend(folderForm, Ext.form.FormPanel);
	
	
	//文件夹弹出win
	var FolderWindow = function() {
		var _win = this;
		this.formPanel = new folderForm();
		var _form = this.formPanel.getForm();
		FolderWindow.superclass.constructor.call(this, {
			title : '创建/修改文件夹',
			width : 300,
			height : 120,
			resizable : true,
			plain : false,
			border : false,
			modal : true,
			autoScroll : false,
			layout : 'fit',
			closeAction : 'hide',
			items : this.formPanel,
			buttonAlign:'center',
			buttons : 
			[
				{	text : ' 保存',
					handler : function() 
					{
						if (_form.isValid()) 
						{
							var form = folderWindow.formPanel.getForm().getValues(false);
							FolderBo = {};
							FolderBo.folderName = form.strFolderName;
							FolderBo.folderId = form.strFolderID;
							FolderBo.parentId = form.strParentFolderID;
							FolderBo.userId = "<%=strUserId%>";							
							JFolderBeb.createFolder(FolderBo,function(data)
							{
								if(data)
	          					{
	          						_win.hide();
	          						Ext.Msg.alert('成功',"操作成功！",function()
	          						{
										if(treePanel.getSelectionModel().getSelectedNode().parentNode)
											treePanel.getSelectionModel().getSelectedNode().parentNode.reload();
										else
											treePanel.getSelectionModel().getSelectedNode().reload();										
										treePanel.expandAll() ;	
	          						}); 
	          					}else
	          					{
	          						Ext.Msg.alert("失败","操作失败!");
	          					}	
							})
						}
					}
				},{
					text : '取消',
					handler : function() {
						_win.hide();
					},
					tooltip : '关闭对话框'
				}
			]	
		});
	}
	Ext.extend(FolderWindow, Ext.Window);

	folderWindow = new FolderWindow();
	
	function createChild()
	{
		var data = {'strFolderID':"",
					'strParentFolderID':treePanel.getSelectionModel().getSelectedNode().id,
					'strFolderName':""
					};
		var record = new Ext.data.Record(data);
		folderWindow.show();
		folderWindow.formPanel.getForm().loadRecord(record);				
	}	 
	function updateNode()
	{
		var selectNode = treePanel.getSelectionModel().getSelectedNode();
		var data = {'strFolderID':selectNode.id,
					'strParentFolderID':"",
					'strFolderName':selectNode.text
					};
		var record = new Ext.data.Record(data);
		folderWindow.show();
		folderWindow.formPanel.getForm().loadRecord(record);		
	}
	function removeNode()
	{
		var selectNode = treePanel.getSelectionModel().getSelectedNode();
		if(selectNode.childNodes.length > 0)
		{
			Ext.Msg.alert("提示","该文件夹还有子目录，请从最底层开始删除!");
			return ;
		}
		var strFolderId = selectNode.id;
		Ext.MessageBox.confirm('删除确认', '确认删除该文件夹?', 
    	    function(btn) 
    	    {
				if(btn == 'yes') 
				{
					JFolderBeb.deleteFolder(strFolderId,function(data)
					{
						if(data)
	  					{
	  						Ext.Msg.alert('成功',"文件夹删除成功！",function()
	  						{								
	  							selectNode.parentNode.reload();
								treePanel.expandAll() ;	
	  						}); 
	  					}else
	  					{
	  						Ext.Msg.alert("失败","文件夹删除失败!");
	  					}	
					})
    	    	}	
    	    });	
	}
	
	
	var sm = new Ext.grid.CheckboxSelectionModel({singleSelect: true});	
	var recordType = Ext.data.Record.create([								
                			   {name: 'id', type: "string"},
                	           {name: 'fileName', type: "string"},
                	           {name: 'uploadTime', mapping: 'uploadTime', type: 'date', dateFormat: 'Y/m/d'},//文件上传时间
                	           {name: 'userId', type: "string"},
                	           {name: 'isShare', type: "string"},
                	           {name: 'shareBeginTime', mapping: 'shareBeginTime', type: 'date', dateFormat: 'Y/m/d'},
                	           {name: 'shareEndTime', mapping: 'shareEndTime', type: 'date', dateFormat: 'Y/m/d'}
                	     ]);

	var cm  = new Ext.grid.ColumnModel(
			[
				sm,
	            {header: "文件名", width: 300, sortable: true, dataIndex: 'fileName',align:'left'},	            
	            {header: "上传时间", width: 80, sortable: true, dataIndex: 'uploadTime',renderer: Ext.util.Format.dateRenderer('Y-m-d'),align:'left'},
	            {header: "上传人", width: 80, sortable: true, dataIndex: 'userId',align:'left'},	
	            {header: "共享开始时间", width: 80, sortable: true, dataIndex: 'shareBeginTime',renderer: Ext.util.Format.dateRenderer('Y-m-d'),align:'left'},
	            {header: "共享结束时间", width: 80, sortable: true, dataIndex: 'shareEndTime',renderer: Ext.util.Format.dateRenderer('Y-m-d'),align:'left'},
				{header: "删除", width: 50, sortable: false, dataIndex: 'id',renderer: showDelete},	
				{header: "下载", width: 50, sortable: false, dataIndex: 'id',renderer: showDownload}				
			]
		);
	
	function showDelete(fileId)
	{
		return "<input type='button' value='删除' class='x-btn button' onclick='doDeleteFle(\"" + fileId  +   "\")'>";  
	}
	
	
	function showDownload(value, cellmeta, record, rowIndex, columnIndex, store) 
	{   
		var isShare = record.get("isShare");
		var str = "";
		if(isShare =="true")	
			str = "<input type='button' value='下载' class='x-btn button' onclick='downLoadFile(\"" + value  +   "\")'>";      
		return str;  
	} 
	
	function formatDate(date)
	{
		if(date != null)
			return "";
		else
			return "";
	}
	
	ds = new Ext.data.Store({
	        proxy: new Ext.data.DWRProxy(JFolderBeb.getContents, true),	
	        reader: new Ext.data.ListRangeReader({
	            totalProperty: 'totalSize',
	            id: 'id'
	        }, recordType),
	        sortInfo:{field:'id', direction:'ASC'}// 排序信息
	    });
     var btnUpload = new  Ext.Button({
					text:'文件上传',
					pressed:true,
					iconCls:'add',//按钮图标的CSS名称						 
					handler:showUploadWin// 点击按钮执行的操作
				});
	var btnShare = new Ext.Button({
					text:'文件共享',
					pressed:true,
					iconCls:'silk-add',//按钮图标的CSS名称						 
					handler:shareFile// 点击按钮执行的操作
				});		
	var btnEdit = new Ext.Button({
					text:'修改文件名',
					pressed:true,
					iconCls:'silk-add',//按钮图标的CSS名称						 
					handler:gridRowDBLClick// 点击按钮执行的操作
				});					
	 var contentDiv = Ext.get("contentDiv");
	 var grid = new Ext.grid.GridPanel({
	    	el: 'contentDiv',	    	
	        ds: ds,
	        cm: cm,
			sm:sm,
			title: '文档资料 ',
		    width: contentDiv.getComputedWidth(),			
			//height: 520, 
			height: contentDiv.getComputedHeight(), 
	        frame:false,
			border:false,
	        collapsible:true,
			autoExpandColumn:1, 
	        enableDragDrop:false, 
			tbar: [
				'查询: ', ' ',
				new Ext.ux.form.SearchField({
					store: ds,
					width:320
				}),
				{xtype:"tbseparator"},
				btnUpload,
				'-',
				btnShare,
				'-',
				btnEdit],
			bbar: new Ext.PagingToolbar({
			        pageSize: 17,
			        store: ds,
			        displayInfo: true,
			        displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
			        emptyMsg: "没有记录"
			    })
					
				
	    });
	    
		
		
		function deleteFile()
		{
			var record = grid.getSelectionModel().getSelected();// 返回值为 Record 类型
			if(!record)
			{
				Ext.Msg.alert("提示","请先选择要删除的文件!");
				return;
			}
			var fileID = record.get("id");	
			// 弹出对话框警告
			if(record) {
				Ext.MessageBox.confirm('确认删除', '确认删除该文件?', 
	    	    	function(btn) {
		    	     if(btn == 'yes') // 选中了是按钮	
			    	 {	    	     	
		    	    	 JFolderBeb.deleteFile(fileID, function(data) {
			    	     if(data) {							    	     		
			    	    	 ds.load({params:{start:0,limit:17, id:selectFolderId,strUserID:'<%=strUserId%>'}});
						 }else 
						 {
							Ext.Msg.alert("删除失败","数据删除失败!");
						 }
						 });
					 	
					 }
					}
				);
			}
		}

	    // render it
	    grid.render();
		var strID = "0";
		ds.on('beforeload', function() {
			  ds.baseParams = {
					id:0,
					start:0,
					limit:17,
					strUserID:'<%=strUserId%>'
			  };
			});		
		
		ds.load({params:{start:0,limit:17, id:0,strUserID:'<%=strUserId%>'}});
		
		
		 treePanel.on('click',function(node)
		 {
				btnAddFolder.enable();
				if(node.id !== '0' && !node.firstChild)
				{
					btnEditFolder.enable();
					btnDeleteFolder.enable();
				}else
				{
					btnEditFolder.disable();
					btnDeleteFolder.disable();
				}
				btnUpload.enable();
				btnShare.enable();
				btnEdit.enable();
				node.expand();      
				var check = node.attributes.checked
				checkchange(node,!check);
				selectFolderId = node.id;	
				ds.on('beforeload', function() {
					  ds.baseParams = {
							id:node.id, 
							limit:17,
							strUserID:'<%=strUserId%>'
					  };
					});						
				ds.load({params:{start:0,limit:17, id: selectFolderId,strUserID:'<%=strUserId%>'}});
				//treeCom.getSelectionModel().clearSelections() ;
				treeOther.getSelectionModel().clearSelections() ;
				grid.getColumnModel().setHidden(6,false);
				grid.setTitle("个人文档");
				
		}); 
		
		treeOther.on('click',function(node)
		 {
		 
			btnAddFolder.disable();
			btnEditFolder.disable();
			btnDeleteFolder.disable();
		 
			btnUpload.disable();
			btnShare.disable();
			btnEdit.disable();
			selectFolderId = node.id;	
			ds.on('beforeload', function() {
				  ds.baseParams = {
						id:node.id, 
						limit:17,
						strUserID:'<%=strUserId%>'
				  };
				});						
			ds.load({params:{start:0,limit:17, id: selectFolderId,strUserID:'<%=strUserId%>'}});
			treePanel.getSelectionModel().clearSelections() ;			
			grid.getColumnModel().setHidden(6,true);
			grid.setTitle("他人共享文档");

		}); 
		
		//文件共享form				
		ShareForm = function(){
				this.idTextField = {
						xtype : 'hidden',
						fieldLabel : "strFileID",
						readOnly : true,
						name : "strFileID"
					};
				this.shareBeginTimeTextField = {
						xtype : 'datefield',
						fieldLabel : "开始时间", 
						name : "shareBeginTime",
						width:160,
						format:'Y-m-d',
						allowBlank : false,
						anchor:'90%',
						blankText :'请输入文件共享开始时间！'
				};	
				
				this.shareEndTimeTextField = {
						xtype : 'datefield',
						fieldLabel : "结束时间", 
						name : "shareEndTime",
						anchor:'90%',
						format:'Y-m-d' 
				};						
				
				ShareForm.superclass.constructor.call(this, {
						bodyStyle : 'padding:5px 5px 0',
						frame : true,
						id: 'ShareForm',
						labelAlign: 'right',
						labelWidth:60,
						items : [this.idTextField, 
						         this.shareBeginTimeTextField,
						         this.shareEndTimeTextField
								 ]
					});	
		}	
		
		Ext.extend(ShareForm, Ext.form.FormPanel);
		
		//文件共享设置弹出win
		var ShareWindow = function() {
			var _win = this;
			this.formPanel = new ShareForm();
			var _form = this.formPanel.getForm();
			ShareWindow.superclass.constructor.call(this, {
				title : '设置文件共享时间',
				width : 300,
				height : 150,
				resizable : true,
				plain : false,
				border : false,
				modal : true,
				autoScroll : false,
				layout : 'fit',
				closeAction : 'hide',
				items : this.formPanel,
				buttonAlign:'center',
				buttons : 
				[
					{	text : ' 保存',
						handler : function() 
						{
							if (_form.isValid()) 
							{
								var form = _form.getValues(false);
								FileBo = {};
								var beginTime =  form.shareBeginTime;	
								var endTime =  form.shareEndTime;	
								var shareBeginTimeDate = null;
								var shareEndTimeDate = null;
																
								if(beginTime != "")	
								{
									var arrBeginTime = beginTime.split("-");	
									shareBeginTimeDate = new Date();		
									var yearOth = arrBeginTime[0];
									var monthOth = arrBeginTime[1];
									var dayOth = arrBeginTime[2];
									shareBeginTimeDate.setFullYear(yearOth,monthOth-1,dayOth);
								}
								if(endTime != "")
								{
									var arrEndTime = endTime.split("-");	
									shareEndTimeDate = new Date();		
									var yearOth = arrEndTime[0];
									var monthOth = arrEndTime[1];
									var dayOth = arrEndTime[2];
									shareEndTimeDate.setFullYear(yearOth,monthOth-1,dayOth);
									
									if(shareBeginTimeDate >= shareEndTimeDate)
									{
										Ext.Msg.alert("警告","共享开始时间必须在结束时间之前!");
										return;
									}
								}
								
								FileBo.fileId = grid.getSelectionModel().getSelected().id;
								FileBo.shareBeginTime = shareBeginTimeDate;
								FileBo.shareEndTime = shareEndTimeDate;						
								JFolderBeb.setFileShare(FileBo,function(data)
								{
									_win.hide();
									if(data)
									{										
										Ext.Msg.alert('成功',"操作成功！",function()
										{
											ds.load({params:{start:0,limit:17,id: selectFolderId,strUserID:'<%=strUserId%>'}});
										}); 
									}else
									{
										Ext.Msg.alert("失败","操作失败!");
									}	
								})
							}
						}
					},{
						text : '取消',
						handler : function() {
							_win.hide();
						},
						tooltip : '关闭对话框'
					}
				]	
			});
		}
		Ext.extend(ShareWindow, Ext.Window);
		var shareWindow = new ShareWindow();
		function shareFile()
		{
			var record = grid.getSelectionModel().getSelected();// 返回值为 Record 类型
			if(!record)
			{
				Ext.Msg.alert("提示","请选择要共享的文件!");
				return;
			}

			
			var data = {'strFileID':record.get("id"),
						'shareBeginTime':record.get("shareBeginTime"),
						'shareEndTime':record.get("shareEndTime")
						};
			var record = new Ext.data.Record(data);
			shareWindow.show();
			shareWindow.formPanel.getForm().loadRecord(record);				
			
		}
		
		
	var EditForm = function(){
			this.idTextField = {
					xtype : 'hidden',
					fieldLabel : "strFileID",
					readOnly : true,
					name : "id"
				};
			this.fileNameTextField = {
					xtype : 'textfield',
					fieldLabel : "文件名",
					allowBlank : false,
					name : "fileName",
					width:260,
					blankText :'请输入文件名'
			};
			
			EditForm.superclass.constructor.call(this, {
					bodyStyle : 'padding:5px 5px 0',
					frame : true,
					id: 'EditForm',
					labelAlign: 'right',
					labelWidth:60,
					items : [this.idTextField, 
							 this.fileNameTextField
							 ]
				});	
	}
	Ext.extend(EditForm, Ext.form.FormPanel);	
	var EditWindow = function() {
		var _win = this;
		this.formPanel = new EditForm();
		var _form = this.formPanel.getForm();
		EditWindow.superclass.constructor.call(this, {
			title : '修改文件名',
			width : 400,
			height : 120,
			resizable : true,
			plain : false,
			border : false,
			modal : true,
			autoScroll : false,
			layout : 'fit',
			closeAction : 'hide',
			items : this.formPanel,
			buttonAlign:'center',
			buttons : 
			[
				{	text : ' 保存',
					handler : function() 
					{
						if (_form.isValid()) 
						{
							var form = _form.getValues(false);
							FileBo = {};
							FileBo.fileId =  form.id;	
							FileBo.fileName =  form.fileName;				
							JFolderBeb.editFileName(FileBo,function(data)
							{
								_win.hide();
								if(data)
								{										
									Ext.Msg.alert('成功',"操作成功！",function()
									{
										ds.load({params:{start:0,limit:17,id: selectFolderId,strUserID:'<%=strUserId%>'}});
									}); 
								}else
								{
									Ext.Msg.alert("失败","操作失败!");
								}	
							})
						}
					}
				},{
					text : '取消',
					handler : function() {
						_win.hide();
					},
					tooltip : '关闭对话框'
				}
			]	
		});
	}
	Ext.extend(EditWindow, Ext.Window);
	var fileEditWindow = new EditWindow();	
	//grid.addListener('rowdblclick', gridRowDBLClick, this);  
	function gridRowDBLClick()
	{	    
		var record = grid.getSelectionModel().getSelected();// 返回值为 Record 类型	             	                
		if(!record){
			Ext.Msg.alert("提示","请选择需要修改的文件!");
			return;
		}
		if (record != null) {
			if(!fileEditWindow)
			{
				fileEditWindow = new EditWindow();				
			}
			fileEditWindow.show();			
			fileEditWindow.formPanel.getForm().loadRecord(record);
		} 
	};	
		
		
		

});	

function doDeleteFle(fileID)
{
	Ext.MessageBox.confirm('确认删除', '确认删除该文件?', 
		function(btn) {
		 if(btn == 'yes') // 选中了是按钮	
		 {	    	     	
			 JFolderBeb.deleteFile(fileID, function(data) {
			 if(data) {							    	     		
				 ds.load({params:{start:0,limit:17,id:selectFolderId,strUserID:'<%=strUserId%>'}});
			 }else 
			 {
				Ext.Msg.alert("删除失败","数据删除失败!");
			 }
			 });
			
		 }
		}
	);
}


function downLoadFile(strFileID)
{	
	document.getElementById("strDownFileID_ID").value = strFileID;
	document.getElementById("downForm").submit();			
}


  </script>
</body>  
</html>
